<%@include file="startUpIncludes.jsp" %>
<%@taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
        <title>
           View Lead
        </title>
    <script type="text/javascript" src="../js/modalwin.js">
    </script>
        <script type="text/javascript">
    function getAjaxCities() {
      //  alert($('#country').val());
        var selectedCountry = $('#country').val();
 
        $.ajax({
        type: "POST",

        url: "/sales/s/leadFormCityCountry",
        data: "selectedCountry="+selectedCountry,
        success: function(response){
      var cities = response.split('***');
      var Ids = cities[0];
      var Names = cities[1];
      var cityIds = Ids.split("?");
      var cityNames = Names.split("?");
     // alert(cityIds[0]);
      //alert(cityNames[0]);
      $('#city').html('');
      jQuery.each(cityIds , function(index, value){
    	     var option = "<option value='" + value + "'>" + cityNames[index] + "</option>";
    	      	$('#city').append(option);
    	});
        },
        error: function(e){
        //alert('Error: ' + e);
        }
        });
        }
    </script>
    </head>
    <body>
    <jsp:include page="header.jsp" >
		<jsp:param value="true" name="loggedIn"/>
	</jsp:include>
    <div class="modal-win-bg">
        <div class="modal-win-box">
            <div class="modal-win-hd">
                <span class="modal-win-title"></span>
                <span class="modal-win-close">x</span>
            </div>
            <div class="modal-win-content"></div>
            <a class="form-btn modal-win-ok">OK</a>
        </div>
    </div>
    <div class="wrap">
	<div class="fitBG">
        <div class="main">
		<%@include file="basicLeftMenu.jsp" %>
            <div class="content">
				<jsp:include page="tabs.jsp" >
					<jsp:param value="leads" name="currentPage"/>
				</jsp:include>
                <div class="tab-content">
                <h3> View Lead</h3>
                
				<div class="lead-view">

				<%--<form name="newAction" action="/sales/s/new-action-eg" method="post">
				<span>Add Action: </span>
				<select class="TB" name="actionType">
                <c:forEach items="${ actionTypes }" var="actionType">
					<option value="${ actionType.id }">${ actionType.name }</option>
				</c:forEach>
				</select>
				<input type="hidden" name="parentId" value="${lead.id}"/>
				<input type="submit" value="GO" class="inf"/>
				</form> --%>
				<%-- <a href="#">Edit Selected View</a>



				<a href="new-action-type">Create New Action Type</a> --%>
				<shiro:hasRole name="callAdd">
				<a href="/sales/s/new-call?parentId=${lead.id}&parentType=lead">Add Call</a>
				</shiro:hasRole>
	           	 	<shiro:hasRole name="appointmentAdd">
	           	 	<a href="/sales/s/new-appointment?parentId=${lead.id}&parentType=lead">Add Appointment</a>
	           	 	</shiro:hasRole>	
				</div>
				

                <form class="new-lead-form" method="post" action="/sales/s/viewLead">
                <div class="btns">

                <a href="/sales/s/leads" class="form-btn">Back</a>
                </div>
                <div class="form-row">
                    <h4>Required Information</h4>
                    <input type="hidden" name="id" value="${lead.id}"/>
                    <div class="info"><label>Lead Owner: </label><span>${userDetails.fName}</span></div>
                    <div class="input-col">
                        <label>First Name: </label>
                        <span>${lead.fName}</span>
                        <label>Last Name: </label>
                        <span>${lead.lName}</span>
                      
                    </div>
                    <div class="input-col">
                        <label>Company: </label>
                        <span>${lead.companyName}</span>
                        <label>Lead Status: </label>
                       	<c:choose>
                       	<c:when test="${lead.leadStatus=='--none--'}">
                       		<span>  </span>
                       	</c:when>
                       	<c:otherwise>
							<span>${lead.leadStatus}</span>                       		
                       	</c:otherwise>	
                       	</c:choose>

                    </div>
                </div>
                <div class="form-row">
                    <h4>Lead Information</h4>
                    <div class="input-col">
                        <label>Title: </label>
                        <span>${lead.title}</span>
                        <label>Phone: </label>
                        <span>${lead.phone}</span>
                        <label>Mobile: </label>
                        <span>${lead.mobile}</span>
                    </div>
                    <div class="input-col">
                        <label>Email: </label>
                        <span>${lead.email}</span>
                        <label>Rating: </label>
                        <c:choose>
                       	<c:when test="${lead.rating=='--none--'}">
                       		<span>  </span>
                       	</c:when>
                       	<c:otherwise>
							<span>${lead.rating}</span>                       		
                       	</c:otherwise>	
                       	</c:choose>
                       <label>Sector: </label>
                         <span>${lead.industry}</span>
                    </div>

                </div>
                <div class="form-row">
                    <h4>Address Information</h4>
                    <div class="input-col">
                        <label>Street: </label>
                     	<span>${lead.street}</span>
                        <label>Country: </label>
                        	<c:choose>
                       	<c:when test="${lead.country.countryName=='--none--'}">
                       		<span>  </span>
                       	</c:when>
                       	<c:otherwise>
							<span>${lead.country.countryName}</span>                       		
                       	</c:otherwise>	
                       	</c:choose>
                          <label>Area: </label>
                       <span>${lead.state}</span>
                    </div>
                    <div class="input-col">
                        <label>Zip/Postal Code: </label>
                        <span>${lead.zipCode}</span>
                        <label>City: </label>
                        <span>${lead.city.name}</span>
                        <label>Website: </label>
                       <span>${lead.webSite}</span>
                    </div>
                </div>
                <div class="form-row">
                    <h4>Additional Information</h4>
                    <div class="input-col">
                        <label>In/Out Bound: </label>
                        <span>${lead.inOutBound}</span>
                        <label>Lead Need's Amount: </label>
                        <c:choose>
                       	<c:when test="${lead.carsNum=='--none--'}">
                       		<span>  </span>
                       	</c:when>
                       	<c:otherwise>
							<span>${lead.carsNum}</span>                       		
                       	</c:otherwise>	
                       	</c:choose>
                        <label>Category: </label>
                        <span>${lead.category}</span>
                        <label>Lead Source: </label>
                        <c:choose>
                       	<c:when test="${lead.leadSource=='--none--'}">
                       		<span>  </span>
                       	</c:when>
                       	<c:otherwise>
							<span>${lead.leadSource}</span>                       		
                       	</c:otherwise>	
                       	</c:choose>
                    </div>
                    <div class="input-col">
                        <label>No. of Employees: </label>
                        <span>${lead.numOfEmp}</span>
                        <label>Annual Revenue: </label>
                        <span>${lead.annualRevenue}</span>
                        <label>Description: </label>
                        <span>${lead.description}</span>
                    </div>
                </div>
                <div class="form-row">
                <h4>Calls</h4>
	                <c:choose>
	                <c:when test="${empty calls}">
	                <div class="noData">No data to preview...</div>
	                </c:when>
	                <c:otherwise>
                    <div class="scroll-table">
                    <table class="recent-leads">
                        <thead>
                            <tr>
                                <th>Action</th>
                                <th>CRM Staff</th>
                                <th>Contacted Person</th>
                                <th>Date</th>
                                <th>In/Out</th>
                                <th>Next Follow Up</th>
                            </tr>
                        </thead>
                        <tbody>
                        <c:forEach items="${calls}" var="call">
                            <tr class="even">

                                <td><%--<a href="/sales/s/viewCall?id=${call.id }&parentId=${lead.id}&parentType=lead">View</a>--%>
                                <shiro:hasRole name="callView">
                                <a href="/sales/s/view-call?id=${call.id}&parentId=${lead.id}&parentType=lead">View</a>
                                </shiro:hasRole>
	                            <shiro:hasRole name="callEdit">
	                            <a href="/sales/s/edit-call?id=${call.id}&parentId=${lead.id}&parentType=lead">Edit</a>
	                            </shiro:hasRole>    	
                                		<%-- <a href="/sales/s/deleteContact?id=${contact.id}">Delete</a>--%>
                                </td>
                                <td>${call.crmStaff.fName}</td>
                                <td>${call.contactedPerson.fName}</td>
                                <c:choose>
		                        	<c:when test="${call.date==null}">
		                        		<td>  </td>
		                        	</c:when>
		                        	<c:otherwise>
		                        	<c:set var="date" value="${call.date}"/>
										<c:set var="datesubstring" value="${fn:substring(date, 0, 10)}" />
				                        <c:set var="datesplit" value="${fn:split(datesubstring, '-')}" />
				                        <c:set var="day" value="${datesplit[2]}" />
										<c:set var="month" value="${datesplit[1]}" />
										<c:set var="year" value="${datesplit[0]}" />
				                        <td>${day}/${month}/${year}</td>             		
		                        	</c:otherwise>
		                        </c:choose>                 
                                <td>
                                	<c:choose>
			                        	<c:when test="${call.inOutCall == true}">In</c:when>
			                        	<c:when test="${call.inOutCall == false}">Out</c:when>
			                        	<c:otherwise>  </c:otherwise>
			                        </c:choose>
								</td>
                                <td>
                                <c:choose>
		                        	<c:when test="${call.nextFollowUp == true}">Yes</c:when>
		                        	<c:when test="${call.nextFollowUp == false}">No</c:when>
		                        	<c:otherwise>  </c:otherwise>
		                        </c:choose>
		                        </td>
                            </tr>
						</c:forEach>
                        </tbody>
                    </table>
                    </div>
                    </c:otherwise>
                    </c:choose>
                </div>
                <div class="form-row">
                <h4>Appointments</h4>
	                <c:choose>
	                <c:when test="${empty appointments}">
	                <div class="noData">No data to preview...</div>
	                </c:when>
	                <c:otherwise>
                    <div class="scroll-table">
                    <table class="recent-leads">
                        <thead>
                            <tr>
                                <th>Action</th>
                                <th>Sales Man</th>
                                <th>Contacted Person</th>
                                <th>Date</th>
                                <th>Meeting Done</th>
                                <th>Deal Closing Done</th>
                                <th>Next Follow Up</th>
                            </tr>
                        </thead>
                        <tbody>
                        <c:forEach items="${appointments}" var="appointment">
                            <tr class="even">
                                <td><%--<a href="/sales/s/view-appointment?id=${appointment.id }&parentId=${lead.id}&parentType=lead">View</a>--%>
	                                	<shiro:hasRole name="appointmentView">
	                                	<a href="/sales/s/view-appointment?id=${appointment.id }&parentId=${lead.id}&parentType=lead">View</a>
	                                	</shiro:hasRole>
	                                	<shiro:hasRole name="appointmentEdit">
	                                	<a href="/sales/s/edit-appointment?id=${appointment.id }&parentId=${lead.id}&parentType=lead">Edit</a>
	                                	</shiro:hasRole>
                                </td>
                                <td>${appointment.salesMan.fName}</td>
                                <td>${appointment.contactedPerson.fName}</td>
                                <%-- <script type="text/javascript">
										function calculate()
										{
											var date = "${appointment.date}";
											//alert(date);
											var datesubstring = date.substring(0,10);
											//alert(datesubstring);
											var datesplit = datesubstring.split("-");
											//alert(datesplit);
											var datefinal =  datesplit[2]+"/"+datesplit[1]+"/"+datesplit[0];
											document.getElementById("appointmentdate").firstChild.nodeValue = datefinal;
										}
										window.onload = calculate;
								</script>--%>
                                <%--<td id="appointmentdate">&nbsp;</td> --%>
                                <c:choose>
		                        	<c:when test="${appointment.date==null}">
		                        		<td>  </td>
		                        	</c:when>
		                        	<c:otherwise>
		                        	<c:set var="date" value="${appointment.date}"/>
										<c:set var="datesubstring" value="${fn:substring(date, 0, 10)}" />
				                        <c:set var="datesplit" value="${fn:split(datesubstring, '-')}" />
				                        <c:set var="day" value="${datesplit[2]}" />
										<c:set var="month" value="${datesplit[1]}" />
										<c:set var="year" value="${datesplit[0]}" />
				                        <td>${day}/${month}/${year}</td>             		
		                        	</c:otherwise>
		                        </c:choose>
                                <td>
                                <c:choose>
			                        	<c:when test="${appointment.meetingDone == true}">Yes</c:when>
			                        	<c:when test="${appointment.meetingDone == false}">No</c:when>
			                        	<c:otherwise>  </c:otherwise>
			                        </c:choose>
                                </td>
                                <td>
                                <c:choose>
			                        	<c:when test="${appointment.dealClosingDone == true}">Yes</c:when>
			                        	<c:when test="${appointment.dealClosingDone == false}">No</c:when>
			                        	<c:otherwise>  </c:otherwise>
			                        </c:choose>
                                </td>
                                <td>
                                <c:choose>
		                        	<c:when test="${appointment.nextFollowUp == true}">Yes</c:when>
		                        	<c:when test="${appointment.nextFollowUp == false}">No</c:when>
		                        	<c:otherwise>  </c:otherwise>
		                        </c:choose>
		                        </td>
                            </tr>
						</c:forEach>
                        </tbody>
                    </table>
                    </div>
                    </c:otherwise>
                    </c:choose>
                </div>
                <div class="btns">

                <a href="/sales/s/leads" class="form-btn">Back</a>
                </div>
                </form>
                </div>
            </div>
        </div>
        
	<%@include file="footer.jspf" %>
    </div>
    </div>

    </body>
</html>